package com.zhan.ielts.web.controller.talkingdata;

import com.zhan.frame.core.dao.BaseService;
import com.zhan.frame.core.web.controller.BaseControllerImpl;
import com.zhan.frame.core.web.domain.Result;
import com.zhan.frame.core.web.domain.Result.Status;
import com.zhan.ielts.domain.talkingdata.TalkingDataAdTrack;
import com.zhan.ielts.service.talkingdata.TalkingDataAdTrackService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/talkingData")
public class TalkingDataController extends BaseControllerImpl<TalkingDataAdTrack, TalkingDataAdTrack> {

	private Logger log = LoggerFactory.getLogger(TalkingDataController.class);

	@Autowired
	private TalkingDataAdTrackService talkingDataAdTrackService;

	@Override
	protected BaseService<TalkingDataAdTrack> getBaseService() {
		return talkingDataAdTrackService;
	}

	@ResponseBody
	@RequestMapping(value = "/register",method = RequestMethod.GET)
	public Result register(TalkingDataAdTrack entity) {
		try {
			entity.setType("register");
			entity.setCreateTime(new Date());
			talkingDataAdTrackService.insert(entity);
			log.info(JSONObject.fromObject(entity).toString());
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(Status.ERROR, "error ===" +e.toString());
		}
		return new Result(Status.OK, "");
	}

	@ResponseBody
	@RequestMapping(value = "/click",method = RequestMethod.GET)
	public Result click(TalkingDataAdTrack entity) {
		try {
			entity.setType("click");
			entity.setCreateTime(new Date());
			talkingDataAdTrackService.insert(entity);
			log.info(JSONObject.fromObject(entity).toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new Result(Status.OK, "");
	}
}
